package in.srain.cube.views.ptr;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

public class SubPtrClassicFrameLayout extends PtrClassicFrameLayout {
 
  private float mDownX;
  private float mDownY;
 
  public SubPtrClassicFrameLayout(Context context) {
    super(context);
  }
 
  public SubPtrClassicFrameLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
  }
 
  public SubPtrClassicFrameLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
  }
 
  @Override
  public boolean dispatchTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
      case MotionEvent.ACTION_DOWN:
        mDownX = ev.getX();
        mDownY = ev.getRawY();
        break;
      case MotionEvent.ACTION_MOVE:
        float moveX = ev.getX();
        float moveY = ev.getRawY();
        float diffX = Math.abs(moveX - mDownX);
        float diffY = Math.abs(moveY - mDownY);
        boolean isHorizon = Math.tan(diffY / diffX) < Math.tan(45.0);
        if (isHorizon) {
          return dispatchTouchEventSupper(ev);
        }
        break;
    }
    return super.dispatchTouchEvent(ev);
  }
 
}